﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件功能描述：基础数据管理Ajax请求服务端处理程序。
  //创建人：赵国伟
  //生成时间：2012/04/21 14:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Shopping.Common;
using Shopping.Model;
using Shopping.BLL;

public partial class Manage_AS_BaseDataCommon : BaseManagePage
{
    private readonly PayModesManage bllPayMode = new PayModesManage();
    private readonly DeliveryManage bllDelivery = new DeliveryManage();
    private ReturnValue ret = new ReturnValue();

    protected void Page_Load(object sender, EventArgs e)
    {
        string action = Request.QueryString["Action"] as string;
        switch (action)
        {
            case "SavePayMode":  //保存一条支付方式信息； by 赵国伟 2012-04-21
                SavePayMode();
                break;
            case "GetPayModeInfo": //查询一条支付方式信息； by 赵国伟 2012-04-21
                GetPayModeInfo();
                break;
            case "DeletePayMode": //删除一条支付方式信息； by 赵国伟 2012-04-21
                DeletePayMode();
                break;
            case "SaveDelivery":     //保存一条支付方式信息； by 赵国伟 2012-04-21
                SaveDelivery();
                break;
            case "GetDeliveryInfo":  //查询一条支付方式信息； by 赵国伟 2012-04-21
                GetDeliveryInfo();
                break;
            case "DeleteDelivery":   //删除一条快递方式信息； by 赵国伟 2012-04-21
                DeleteDelivery();
                break;
            case "DeleteDeliveryFee": //删除一条快递费用信息； by 赵国伟 2012-04-22
                DeleteDeliveryFee();
                break;
            case "GetDeliveryFee": //查询一条快递费设置信息； by 赵国伟 2012-04-22
                GetDeliveryFee();
                break;
            case "SaveDeliveryFee": //保存快递费设置信息； by 赵国伟 2012-04-22
                SaveDeliveryFee();
                break;

        }
        Response.End();
    }

    #region "保存一条支付方式信息  by 赵国伟 2012-04-21"
    /// <summary>
    /// 保存一条支付方式信息
    /// </summary>
    private void SavePayMode()
    {
        ret = BLLHelper.Save<PayModesManage, PayModes>("SavePayMode");
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "查询一条支付方式信息； by 赵国伟 2012-04-21"
    /// <summary>
    /// 查询一条支付方式信息；
    /// </summary>
    private void GetPayModeInfo()
    {
        int PayModeID = Utility.G<int>("PayModeID");
        Response.Write(JSONHelper.ObjectToJson<PayModes>(bllPayMode.GetPayModeInfo(PayModeID)));
    }
    #endregion

    #region "删除一条支付方式信息； by 赵国伟 2012-04-21"
    /// <summary>
    /// 删除一条支付方式信息；
    /// </summary>
    private void DeletePayMode()
    {
        int PayModeID = Utility.G<int>("PayModeID");
        Response.Write(bllPayMode.DeletePayMode(PayModeID).ToJsonString());
    }
    #endregion



    #region "保存一条快递方式信息  by 赵国伟 2012-04-21"
    /// <summary>
    /// 保存一条快递方式信息
    /// </summary>
    private void SaveDelivery()
    {
        ret = BLLHelper.Save<DeliveryManage, Deliveries>("Save");
        Response.Write(ret.ToJsonString());
    }
    #endregion

    #region "查询一条快递方式信息； by 赵国伟 2012-04-21"
    /// <summary>
    /// 查询一条快递方式信息；
    /// </summary>
    private void GetDeliveryInfo()
    {
        int DeliveryID = Utility.G<int>("DeliveryID");
        Response.Write(JSONHelper.ObjectToJson<Deliveries>(bllDelivery.Get(DeliveryID)));
    }
    #endregion

    #region "删除一条快递方式信息； by 赵国伟 2012-04-21"
    /// <summary>
    /// 删除一条快递方式信息；
    /// </summary>
    private void DeleteDelivery()
    {
        int DeliveryID = Utility.G<int>("DeliveryID");
        Response.Write(bllDelivery.Delete(DeliveryID).ToJsonString());
    }
    #endregion



    #region "删除一条指定的快递费用设置； by 赵国伟 2012-04-21"
    /// <summary>
    /// 删除一条指定的快递费用设置；
    /// </summary>
    /// <returns></returns>
    private void DeleteDeliveryFee()
    {
        int DeliveryFeeID = Utility.G<int>("DeliveryFeeID");
        Response.Write(bllDelivery.DeleteDeliveryFee(DeliveryFeeID).ToJsonString());
    }
    #endregion

    #region "查询一条快递费设置信息； by 赵国伟 2012-04-22"
    /// <summary>
    /// 查询一条快递费设置信息；
    /// </summary>
    /// <param name="DeliveryFeesID"></param>
    /// <returns></returns>
    private void GetDeliveryFee()
    {
        int DeliveryFeeID = Utility.G<int>("DeliveryFeeID");
        DeliveryFeeInfo d = bllDelivery.GetDeliveryFee(DeliveryFeeID);
        Response.Write(JSONHelper.ObjectToJson<DeliveryFeeInfo>(d));
    }
    #endregion

    #region "保存一条快递费用设置信息； by 赵国伟 2012-04-22"
    /// <summary>
    /// 保存一条快递费用设置信息；
    /// </summary>
    /// <returns></returns>
    private void  SaveDeliveryFee()
    {
        string jsonOfData = Request.Form["jsonData"] + "";
        string jsonOfAreaIDs = Request.Form["JsonOfAreaIDs"] + "";

        ReturnValue ret = new ReturnValue();
        DeliveryFees d= null;
        List<int> listOfAreaIds = null;
        try
        {
            d = JSONHelper.JsonStringToObject<DeliveryFees>(jsonOfData);
            if (!string.IsNullOrEmpty(jsonOfAreaIDs))
                listOfAreaIds = JSONHelper.JsonStringToObject<List<int>>(jsonOfAreaIDs);

        }
        catch (Exception e)
        {
            ret.Message = "Json反序列化失败 原因:" + e.Message;
            Response.Write(ret.ToJsonString());
            return;
        }
        ret = bllDelivery.SaveDeliveryFee(d, listOfAreaIds);
        Response.Write(ret.ToJsonString());
    }
    #endregion


}